/**
 * MainWindow.java
 * 
 * @author	Joe Scharnitzke
 * Date: 	May 31, 2011
 * 
 * This class defines the attributes for the Main Window that
 * displays on launching the program.
 *
 * Change Log:
 * 	06/10/11 10:57 - (v1.0) Release
 * 	May 31, 2011 10:53:00 AM - (v0.1) Initial Implementation
 */

package gui;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.File;

public class MainWindow extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 1946349350836193907L;
	
	private JPanel jp_buttons = new JPanel(new GridBagLayout());
		private JButton jb_char_sheets = new JButton("Character Sheets");
		private JButton jb_dm_tools = new JButton("DM Tools");
		private JButton jb_exit = new JButton("Exit");
		
	private GridBagConstraints gbc_jp_buttons = new GridBagConstraints();
	
	/**
	 * Default constructor for MainWindow objects.
	 */
	
	public MainWindow()
	{		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle("Gazebo");
		
		//try to load the default logo
		try
		{
			BufferedImage bi_d20 = ImageIO.read(new File("assets/images/d20icon.png"));
			setIconImage(bi_d20);
		}
		
		catch(Exception e)
		{
			System.err.println(e);
		}
		
		jb_char_sheets.addActionListener(this);
		jb_dm_tools.addActionListener(this);
		jb_exit.addActionListener(this);
		
		//add jb_char_sheets
		gbc_jp_buttons.fill = GridBagConstraints.HORIZONTAL;
		gbc_jp_buttons.gridx = 0;
		gbc_jp_buttons.gridy = 0;
		gbc_jp_buttons.insets = new Insets(5, 2, 5, 2);
		jp_buttons.add(jb_char_sheets, gbc_jp_buttons);
		
		//add jb_dm_tools
		gbc_jp_buttons.fill = GridBagConstraints.HORIZONTAL;
		gbc_jp_buttons.gridx = 0;
		gbc_jp_buttons.gridy = 1;
		gbc_jp_buttons.insets = new Insets(5, 2, 5, 2);
		jp_buttons.add(jb_dm_tools, gbc_jp_buttons);
		
		//add jb_exit
		gbc_jp_buttons.fill = GridBagConstraints.HORIZONTAL;
		gbc_jp_buttons.gridx = 0;
		gbc_jp_buttons.gridy = 2;
		gbc_jp_buttons.insets = new Insets(5, 2, 5, 2);
		jp_buttons.add(jb_exit, gbc_jp_buttons);
		
		add(jp_buttons);
		
		setSize(150, 150);
		GUIHelper.Center(this);
		setVisible(true);
	}

	/* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent event)
    {
    	if(event.getSource().equals(jb_char_sheets))
    	{   		
    		new CharSheetWindow();
    	}
    	
    	if(event.getSource().equals(jb_dm_tools))
    	{
    		new DMToolsWindow();
    	}
    	
    	if(event.getSource().equals(jb_exit))
    	{
    		System.exit(0);
    	}
    }

}
